<% layout('/layouts/default.html', {title: '手机信息表管理', libs: ['dataGrid']}){ %>
<div class="main-content">
	<div class="box box-main">
		<div class="box-header">
			<div class="box-title">
				<i class="fa icon-notebook"></i> ${text('手机信息表管理')}
			</div>
			<div class="box-tools pull-right">
				<a href="#" class="btn btn-default" id="btnSearch" title="${text('查询')}"><i class="fa fa-filter"></i> ${text('查询')}</a>
<!--				<a href="#" class="btn btn-default" id="btnSearch2" title="${text('修改状态')}">${text('修改状态')}</a>
				<a href="#" class="btn btn-default" id="btnSearch1" title="${text('多选')}">${text('多选')}</a>-->
				<% if(hasPermi('ele:elePhone:edit')){ %>
				<a href="${ctx}/ele/elePhone/form" class="btn btn-default btnTool" title="${text('新增手机信息表')}"><i class="fa fa-plus"></i> ${text('新增')}</a>
				<% } %>
				<a href="#" class="btn btn-default" id="btnSetting" title="${text('设置')}"><i class="fa fa-navicon"></i></a>
			</div>
		</div>
		<div class="box-body">
			<#form:form id="searchForm" model="${elePhone}" action="${ctx}/ele/elePhone/listData" method="post" class="form-inline hide"
			data-page-no="${parameter.pageNo}" data-page-size="${parameter.pageSize}" data-order-by="${parameter.orderBy}">
			<div class="form-group">
				<label class="control-label">${text('手机编号')}：</label>
				<div class="control-inline">
					<#form:input path="phoneNum" maxlength="64" class="form-control width-120"/>
				</div>
			</div>
			<div class="form-group">
				<label class="control-label">${text('手机名')}：</label>
				<div class="control-inline">
					<#form:input path="phoneName" maxlength="64" class="form-control width-120"/>
				</div>
			</div>
			<div class="form-group">
				<label class="control-label">${text('手机年限')}：</label>
				<div class="control-inline">
					<#form:input path="phoneAge" maxlength="64" class="form-control width-120"/>
				</div>
			</div>
			<div class="form-group">
				<label class="control-label">${text('手机状态')}：</label>
				<div class="control-inline width-120">
					<#form:select path="phoneStatus" dictType="ele_phone_status" blankOption="true" class="form-control"/>
					<#form:checkbox path="phoneStatus" label="是否替换现有文件" class="form-control"/>
				</div>
			</div>
			<div class="form-group">
				<label class="control-label">${text('生成日期')}：</label>
				<div class="control-inline">
					<#form:input path="phoneCreate" readonly="true" maxlength="20" class="form-control laydate width-datetime"
					dataFormat="datetime" data-type="datetime" data-format="yyyy-MM-dd HH:mm"/>
				</div>
			</div>
			<div class="form-group">
				<button type="submit" class="btn btn-primary btn-sm">${text('查询')}</button>
				<button type="reset" class="btn btn-default btn-sm">${text('重置')}</button>
			</div>
		</#form:form>
		<table id="dataGrid"></table>
		<div id="dataGridPage"></div>
	</div>
</div>
</div>
<% } %>
<script>
	// 初始化DataGrid对象
	$('#dataGrid').dataGrid({
		searchForm: $("#searchForm"),
		columnModel: [
			{header:'${text("手机编号")}', name:'phoneNum', index:'a.phone_num', width:150, align:"left", frozen:true, formatter: function(val, obj, row, act){
					return '<a href="${ctx}/ele/elePhone/form?phoneId='+row.phoneId+'" class="btnList" data-title="${text("编辑手机信息表")}">'+(val||row.id)+'</a>';
				}},
			{header:'${text("手机名")}', name:'phoneName', index:'a.phone_name', width:150, align:"left"},
			{header:'${text("手机年限")}', name:'phoneAge', index:'a.phone_age', width:150, align:"left"},
			{header:'${text("手机状态")}', name:'phoneStatus', index:'a.phone_status', width:150, align:"center", formatter: function(val, obj, row, act){
					return js.getDictLabel(${@DictUtils.getDictListJson('ele_phone_status')}, val, '${text("未知")}', true);
				}},
			{header:'${text("生成日期")}', name:'phoneCreate', index:'a.phone_create', width:150, align:"center"},
			{header:'${text("操作")}', name:'actions', width:120, formatter: function(val, obj, row, act){//obj
					var actions = [];
					//<% if(hasPermi('ele:elePhone:edit')){ %>
					actions.push('<a href="${ctx}/ele/elePhone/form?phoneId='+row.phoneId+'" class="btnList" title="${text("编辑手机信息表")}"><i class="fa fa-pencil"></i></a>&nbsp;');
					actions.push('<a href="${ctx}/ele/elePhone/delete?phoneId='+row.phoneId+'" class="btnList" title="${text("删除手机信息表")}" data-confirm="${text("确认要删除该手机信息表吗？")}"><i class="fa fa-trash-o"></i></a>&nbsp;');

					actions.push('<input type="checkbox" name="phoneOption" data-phone-id="' + row.phoneId + '" value="option1" class="multiCheckbox" style="display: none;">&nbsp;');
					console.log(row.phoneId);
					console.log("-------------------");
					console.log(row.phoneName);
					console.log(row.phoneStatus);
					//<% } %>
					return actions.join('');
				}}
		],
		// 加载成功后执行事件
		ajaxSuccess: function(data){

		}
	});
	// 用于存储选中的数据
	let selectedPhones = [];

	// 监听“777”按钮的点击事件
	document.getElementById('btnSearch1').addEventListener('click', function() {

	});

	// 监听复选框的 change 事件
	document.addEventListener('change', function(event) {
		if (event.target.classList.contains('multiCheckbox')) {
			const phoneId = event.target.getAttribute('data-phone-id');
			console.log("--}}}}---");
			console.log(phoneId);
			if (event.target.checked) {
				// 如果复选框被选中，将其添加到 selectedPhones 数组
				if (!selectedPhones.includes(phoneId)) {
					selectedPhones.push(phoneId);
					updateSelectedDataDisplay();
				}
			} else {
				// 如果复选框被取消选中，将其从 selectedPhones 数组中移除
				selectedPhones = selectedPhones.filter(id => id !== phoneId);
				updateSelectedDataDisplay();
			}
			console.log('当前选中的手机ID:', selectedPhones);
		}
	});


	function updateSelectedDataDisplay() {
		console.log('更新后的选中的数据：', JSON.stringify(selectedPhones, null, 2));
	}









	$('#btnSearch2').click(function (){

		// 发送请求
		fetch('${ctx}/ele/elePhone/ups', {
			method: 'POST',
			headers: {
				'Content-Type': 'application/json'
			},
			body: JSON.stringify(selectedPhones)
		})
				.then(response => response.json())
				.then(result => {
					console.log('后端返回的数据:', result);
					if (result.success) {
						alert('操作成功！');
					} else {
						alert('操作失败：' + result.message);
					}
				})
				.catch(error => {
					console.error('请求失败:', error);
					alert('请求失败，请检查网络连接');
				});
	});




	$('#btnSearch1').click(function() {
		$('.multiCheckbox').toggle();
	});
</script>